﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.Mvc;

namespace System.Web.UI
{
	public static class HtmlTextWriterExtensions
	{
		public static void WriteMessages(this HtmlTextWriter writer, ViewDataDictionary viewData)
		{
			if (viewData == null)
				return;
			if (viewData.ContainsKey("messages"))
			{
				writer.AddAttribute(HtmlTextWriterAttribute.Class, "jqmvc-messages");
				writer.RenderBeginTag(HtmlTextWriterTag.Span);
				writer.Write(viewData["messages"].ToUnsortedList());
				writer.RenderEndTag();
			}
			if (viewData.ContainsKey("errors"))
			{
				writer.AddAttribute(HtmlTextWriterAttribute.Class, "jqmvc-errors");
				writer.RenderBeginTag(HtmlTextWriterTag.Span);
				writer.Write(viewData["errors"].ToUnsortedList());
				writer.RenderEndTag();
			}
		}
	}
}
